import React from 'react';
import styles from './index.less';
import { history, formatMessage, useIntl, getDvaApp, withRouter, connectMaster } from 'umi';
import { Button } from 'antd';
import { connect } from 'dva';
import { routerGo } from '@/utils/router';

@connectMaster    //接收主服务数据
@withRouter
@connect(({ }) => ({

}))
export default class extends React.Component {
  componentDidMount() {
    console.log(this.props)
    var store = this.props.masterData.store
    var state = store.getState()
    console.log(state)
  }

  setMasterData = (store) => {
    store.dispatch({
      type: 'user/setState', payload: {
        user: { userId: "被app1修改了" }
      }
    })
  }

  render() {
    var store = this.props.masterData.store
    var { user } = store.getState()

    return (
      <div>
        <span style={{ marginRight: "20px" }}>我是app1 的page1页面</span>

        <Button
          type="primary"
          style={{ marginBottom: "10px" }}
          onClick={() => { history.push('/page2') }}>
          跳转2
        </Button>

        <div style={{ marginBottom: "10px" }}>
          <Button
            type="primary"
            onClick={() => this.setMasterData(store)}
          >修改main数据 userId: {user.user.userId}</Button>
        </div>

        <div style={{ marginBottom: "10px" }}>
          <Button
            type="primary"
            onClick={() => {
              routerGo({
                href: '/home',
              })
            }}
          >跳转main home页面</Button>
        </div>

      </div>
    );
  }
}







